using System;
using System.Collections.Generic;
using System.Text;
using System.Data.Common;
using System.Data;
using XBLib.Dal.AdoDal;
using DataInfo;
using KenLib.Common;
namespace KenLib.Dal
{
    public class 雇用情報Dao : BaseAdoDao
    {
        private string m_requestTime;
        private string m_displayTime;
        public int Insert(雇用情報 obj)
        {
            int i = 0;
            try
            {
                m_requestTime = DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss");
                DbParameter param20 = _daoHelper.CreateParameter("@廃止区分", obj.廃止区分, DbType.Int16);
                DbParameter param1 = _daoHelper.CreateParameter("@雇用区分", obj.雇用区分, DbType.Int32);
                DbParameter param2 = _daoHelper.CreateParameter("@雇用区分名", obj.雇用区分名, DbType.String);
                DbParameter param3 = _daoHelper.CreateParameter("@発令開始日", obj.発令開始日, DbType.DateTime);
                DbParameter param4 = _daoHelper.CreateParameter("@発令終了日", obj.発令終了日, DbType.DateTime);
                DbParameter param5 = _daoHelper.CreateParameter("@実際開始日", obj.実際開始日, DbType.DateTime);
                DbParameter param6 = _daoHelper.CreateParameter("@実際終了日", obj.実際終了日, DbType.DateTime);
                DbParameter param7 = _daoHelper.CreateParameter("@変更理由", obj.変更理由, DbType.String);
                DbParameter param8 = _daoHelper.CreateParameter("@社員ID", obj.社員ID, DbType.Int32);
                DbCommand command = _daoHelper.CreateCommand(CommandNameManager.Insert_HumanContractTypeInfo, CommandType.StoredProcedure, param1, param2, param3, param4, param5, param6, param7, param8, param20);
                i = _daoHelper.Execute(command);
                m_displayTime = DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss");
                ExportFile.WriteLog("", "", "INSERT", "Insert_HumanContractTypeInfo", m_requestTime, m_displayTime);
            }
            catch (Exception ex)
            {
                m_displayTime = DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss");
                ExportFile.WriteErr("", "", "SELECT", ex.Message, m_requestTime, m_displayTime);
            }
            return i;
        }

        public int Update(雇用情報 obj)
        {
            int i = 0;
            try
            {
                m_requestTime = DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss");
                DbParameter param20 = _daoHelper.CreateParameter("@廃止区分", obj.廃止区分, DbType.Int16);
                DbParameter param0 = _daoHelper.CreateParameter("@ID", obj.ID, DbType.Int32);
                DbParameter param1 = _daoHelper.CreateParameter("@雇用区分", obj.雇用区分, DbType.Int32);
                DbParameter param2 = _daoHelper.CreateParameter("@雇用区分名", obj.雇用区分名, DbType.String);
                DbParameter param3 = _daoHelper.CreateParameter("@発令開始日", obj.発令開始日, DbType.DateTime);
                DbParameter param4 = _daoHelper.CreateParameter("@発令終了日", obj.発令終了日, DbType.DateTime);
                DbParameter param5 = _daoHelper.CreateParameter("@実際開始日", obj.実際開始日, DbType.DateTime);
                DbParameter param6 = _daoHelper.CreateParameter("@実際終了日", obj.実際終了日, DbType.DateTime);
                DbParameter param7 = _daoHelper.CreateParameter("@変更理由", obj.変更理由, DbType.String);
                DbParameter param8 = _daoHelper.CreateParameter("@社員ID", obj.社員ID, DbType.Int32);
                DbCommand command = _daoHelper.CreateCommand(CommandNameManager.Update_HumanContractTypeInfo, CommandType.StoredProcedure, param0, param1, param2, param3, param4, param5, param6, param7, param8, param20);
                i = _daoHelper.Execute(command);
                m_displayTime = DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss");
                ExportFile.WriteLog("", "", "UPDATE", "Update_HumanContractTypeInfo", m_requestTime, m_displayTime);
            }
            catch (Exception ex)
            {
                m_displayTime = DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss");
                ExportFile.WriteErr("", "", "SELECT", ex.Message, m_requestTime, m_displayTime);
            }
            return i;
        }

        public int Delete(int id)
        {
            int i = 0;
            try
            {
                m_requestTime = DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss");
                DbParameter param0 = _daoHelper.CreateParameter("@ID", id, DbType.Int32);

                DbCommand command = _daoHelper.CreateCommand(CommandNameManager.Delete_HumanContractTypeInfo, CommandType.StoredProcedure, param0);
                i = _daoHelper.Execute(command);
                m_displayTime = DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss");
                ExportFile.WriteLog("", "", "DELETE", "Delete_HumanContractTypeInfo", m_requestTime, m_displayTime);
            }
            catch (Exception ex)
            {
                m_displayTime = DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss");
                ExportFile.WriteErr("", "", "SELECT", ex.Message, m_requestTime, m_displayTime);
            }
            return i;
        }

        public int InsertPartial(雇用情報 obj)
        {
            int i = 0;
            try
            {
                m_requestTime = DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss");
                DbCommand commands = _daoHelper.CreateCommand(CommandNameManager.sp_Insert雇用情報_Partial, CommandType.StoredProcedure);
                DbParameter para1 = _daoHelper.CreateParameter("@廃止区分", obj.廃止区分);
                DbParameter para1_1 = _daoHelper.CreateParameter("@雇用区分", obj.雇用区分);
                DbParameter para2 = _daoHelper.CreateParameter("@雇用区分名", obj.雇用区分名);
                DbParameter para3 = _daoHelper.CreateParameter("@発令開始日", obj.発令開始日);
                DbParameter para4 = _daoHelper.CreateParameter("@実際開始日", obj.実際開始日);
                DbParameter para5 = _daoHelper.CreateParameter("@社員ID", obj.社員ID);
                commands.Parameters.Add(para1);
                commands.Parameters.Add(para1_1);
                commands.Parameters.Add(para2);
                commands.Parameters.Add(para3);
                commands.Parameters.Add(para4);
                commands.Parameters.Add(para5);

                i = _daoHelper.Execute(commands);

                m_displayTime = DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss");
                ExportFile.WriteLog("", "", "INSERT", "sp_Insert雇用情報_Partial", m_requestTime, m_displayTime);
            }
            catch (Exception ex)
            {
                m_displayTime = DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss");
                ExportFile.WriteErr("", "", "INSERT", ex.Message, m_requestTime, m_displayTime);
            }
            return i;
        }

        #region Hunglt
        public void InsertInfo雇用情報(雇用情報 obj, int 社員ID)
        {
            DbParameter param廃止区分 = _daoHelper.CreateParameter("@廃止区分", obj.廃止区分, DbType.Int16);
            DbParameter param発令開始日 = _daoHelper.CreateParameter("@発令開始日", obj.発令開始日, DbType.DateTime);
            DbParameter param発令終了日 = _daoHelper.CreateParameter("@発令終了日", obj.発令終了日, DbType.DateTime);
            DbParameter param実際開始日 = _daoHelper.CreateParameter("@実際開始日", obj.実際開始日, DbType.DateTime);
            DbParameter param実際終了日 = _daoHelper.CreateParameter("@実際終了日", obj.実際終了日, DbType.DateTime);
            DbParameter param社員ID = _daoHelper.CreateParameter("@社員ID", 社員ID, DbType.Int32);

            DbCommand command = _daoHelper.CreateCommand("sp_Insert_雇用情報_Hunglt", CommandType.StoredProcedure,
              param廃止区分, param発令開始日, param発令終了日, param実際開始日, param実際終了日, param社員ID);
            _daoHelper.Query(command);
        }
        public void UpdateInfo雇用情報(雇用情報 obj, int 社員ID)
        {
            DbParameter param廃止区分 = _daoHelper.CreateParameter("@廃止区分", obj.廃止区分, DbType.Int16);
            DbParameter param発令開始日 = _daoHelper.CreateParameter("@発令開始日", obj.発令開始日, DbType.DateTime);
            DbParameter param発令終了日 = _daoHelper.CreateParameter("@発令終了日", obj.発令終了日, DbType.DateTime);
            DbParameter param実際開始日 = _daoHelper.CreateParameter("@実際開始日", obj.実際開始日, DbType.DateTime);
            DbParameter param実際終了日 = _daoHelper.CreateParameter("@実際終了日", obj.実際終了日, DbType.DateTime);
            DbParameter param社員ID = _daoHelper.CreateParameter("@社員ID", 社員ID, DbType.Int32);

            DbCommand command = _daoHelper.CreateCommand("sp_Update_雇用情報_Hunglt", CommandType.StoredProcedure,
              param廃止区分, param発令開始日, param発令終了日, param実際開始日, param実際終了日, param社員ID);
            _daoHelper.Query(command);
        }
        public DataTable Select雇用区分()
        {
            DbCommand dbcommand = _daoHelper.CreateCommand("sp_select_雇用区分_Hunglt", CommandType.StoredProcedure);
            return _daoHelper.Query(dbcommand);
        }
        public void Insert雇用情報(雇用情報 obj)
        {
            DbParameter param廃止区分 = _daoHelper.CreateParameter("@廃止区分", obj.廃止区分, DbType.Int16);
			DbParameter param雇用区分 = _daoHelper.CreateParameter("@雇用区分", obj.雇用区分_s, DbType.String);
            DbParameter param雇用区分名 = _daoHelper.CreateParameter("@雇用区分名", obj.雇用区分名, DbType.String);
            DbParameter param発令開始日 = _daoHelper.CreateParameter("@発令開始日", obj.発令開始日, DbType.DateTime);
            DbParameter param発令終了日 = _daoHelper.CreateParameter("@発令終了日", obj.発令終了日, DbType.DateTime);
            DbParameter param実際開始日 = _daoHelper.CreateParameter("@実際開始日", obj.実際開始日, DbType.DateTime);
            DbParameter param実際終了日 = _daoHelper.CreateParameter("@実際終了日", obj.実際終了日, DbType.DateTime);
            DbParameter param変更理由 = _daoHelper.CreateParameter("@変更理由", obj.変更理由, DbType.String);
            DbParameter param社員ID = _daoHelper.CreateParameter("@社員ID", obj.社員ID, DbType.Int32);

            DbCommand command = _daoHelper.CreateCommand("sp_Insert_雇用情報_FormJ_Hunglt", CommandType.StoredProcedure,
              param廃止区分, param雇用区分, param雇用区分名,
              param発令開始日, param発令終了日, param実際開始日,
              param実際終了日, param変更理由, param社員ID);
            _daoHelper.Query(command);
        }
        public void Update雇用情報(雇用情報 obj, int 雇用情報ID)
        {
            DbParameter param廃止区分 = _daoHelper.CreateParameter("@廃止区分", obj.廃止区分, DbType.Int16);
			DbParameter param雇用区分 = _daoHelper.CreateParameter("@雇用区分", obj.雇用区分_s, DbType.String);
            DbParameter param雇用区分名 = _daoHelper.CreateParameter("@雇用区分名", obj.雇用区分名, DbType.String);
            DbParameter param発令開始日 = _daoHelper.CreateParameter("@発令開始日", obj.発令開始日, DbType.DateTime);
            DbParameter param発令終了日 = _daoHelper.CreateParameter("@発令終了日", obj.発令終了日, DbType.DateTime);
            DbParameter param実際開始日 = _daoHelper.CreateParameter("@実際開始日", obj.実際開始日, DbType.DateTime);
            DbParameter param実際終了日 = _daoHelper.CreateParameter("@実際終了日", obj.実際終了日, DbType.DateTime);
            DbParameter param変更理由 = _daoHelper.CreateParameter("@変更理由", obj.変更理由, DbType.String);
            DbParameter param社員ID = _daoHelper.CreateParameter("@社員ID", obj.社員ID, DbType.Int32);
            DbParameter param雇用情報ID = _daoHelper.CreateParameter("@雇用情報ID", 雇用情報ID, DbType.Int32);

            DbCommand command = _daoHelper.CreateCommand("sp_update_雇用情報_FormJ_Hunglt", CommandType.StoredProcedure,
              param廃止区分, param雇用区分, param雇用区分名,
              param発令開始日, param発令終了日, param実際開始日,
              param実際終了日, param変更理由, param社員ID,
              param雇用情報ID);
            _daoHelper.Query(command);
        }
        public DataTable Select雇用情報_ByID(int 雇用情報ID)
        {
            DbParameter param雇用情報ID = _daoHelper.CreateParameter("@雇用情報ID", 雇用情報ID, DbType.Int32);
            DbCommand dbcommand = _daoHelper.CreateCommand("sp_select_雇用情報_FormJ_Hunglt", CommandType.StoredProcedure, param雇用情報ID);
            return _daoHelper.Query(dbcommand);
        }
        #endregion

        #region HaVanHoat

        /// <summary>
        /// Date: 2012.03.19
        /// </summary>
        /// <param name="obj"></param>
        public int InsertDataOrg40(雇用情報 obj, out int IdCurrent)
        {
            int i = 0;
            IdCurrent = 0;
            DbCommand commands = _daoHelper.CreateCommand("sp_Insert雇用情報_Partial_2_40_Hoat", CommandType.StoredProcedure);
            DbParameter para1 = _daoHelper.CreateParameter("@廃止区分", obj.廃止区分);
            DbParameter para1_1 = _daoHelper.CreateParameter("@雇用区分", obj.雇用区分_1);
            DbParameter para2 = _daoHelper.CreateParameter("@雇用区分名", obj.雇用区分名_1);
            DbParameter para3 = _daoHelper.CreateParameter("@発令開始日", obj.発令開始日_1);
            DbParameter para4 = _daoHelper.CreateParameter("@実際開始日", obj.実際開始日_1);
            DbParameter para5 = _daoHelper.CreateParameter("@社員ID", obj.社員ID);
            DbParameter para6 = _daoHelper.CreateParameter("@ID", 0);
            para6.Direction = ParameterDirection.Output;

            commands.Parameters.Add(para1);
            commands.Parameters.Add(para1_1);
            commands.Parameters.Add(para2);
            commands.Parameters.Add(para3);
            commands.Parameters.Add(para4);
            commands.Parameters.Add(para5);
            commands.Parameters.Add(para6);

            i = _daoHelper.Execute(commands);

            Int32.TryParse(commands.Parameters["@ID"].Value.ToString(), out IdCurrent);

            return i;
        }

        public DataTable ShowDataPageLoadFirstInsertMode(string 社員ID)
        {
            DbCommand commands = _daoHelper.CreateCommand("sp_Select雇用情報_Partial_Insert_Org40_Vh", CommandType.StoredProcedure);
            DbParameter para = _daoHelper.CreateParameter("@社員ID", 社員ID);
            commands.Parameters.Add(para);
            DataTable dt = _daoHelper.Query(commands);
            return dt;
        }

        public DataTable ShowDataPageLoadFirstUpdateMode(string 社員ID, string ID)
        {
            DbCommand commands = _daoHelper.CreateCommand("sp_Select雇用情報_Partial_Update_Org40_Vh", CommandType.StoredProcedure);
            DbParameter para1 = _daoHelper.CreateParameter("@社員ID", 社員ID);
            DbParameter para2 = _daoHelper.CreateParameter("@ID", ID);
            commands.Parameters.Add(para1);
            commands.Parameters.Add(para2);
            DataTable dt = _daoHelper.Query(commands);
            return dt;
        }

        public int UpdateDateOrg39BaseCurrentID(雇用情報 obj)
        {
            int i = 0;
            DbCommand commands = _daoHelper.CreateCommand("sp_Update雇用情報_CurrentID_40_Hoat", CommandType.StoredProcedure);
            
            DbParameter para1_1 = _daoHelper.CreateParameter("@雇用区分", obj.雇用区分_1);
            DbParameter para2 = _daoHelper.CreateParameter("@雇用区分名", obj.雇用区分名_1);
            DbParameter para3 = _daoHelper.CreateParameter("@発令開始日", obj.発令開始日_1);
            DbParameter para4 = _daoHelper.CreateParameter("@実際開始日", obj.実際開始日_1);
            DbParameter para5 = _daoHelper.CreateParameter("@社員ID", obj.社員ID);
            DbParameter para6 = _daoHelper.CreateParameter("@ID", obj.ID);
            
            commands.Parameters.Add(para1_1);
            commands.Parameters.Add(para2);
            commands.Parameters.Add(para3);
            commands.Parameters.Add(para4);
            commands.Parameters.Add(para5);
            commands.Parameters.Add(para6);

            i = _daoHelper.Execute(commands);
            return i;
        }

        public bool CheckSameOrg40(雇用情報 obj)
        {
            DbCommand commands = _daoHelper.CreateCommand("CheckSameOrg40Vh", CommandType.StoredProcedure);
            
            DbParameter para1 = _daoHelper.CreateParameter("@雇用区分", obj.雇用区分_1);
            DbParameter para3 = _daoHelper.CreateParameter("@発令開始日", obj.発令開始日_1);
            DbParameter para4 = _daoHelper.CreateParameter("@実際開始日", obj.実際開始日_1);
            DbParameter para5 = _daoHelper.CreateParameter("@社員ID", obj.社員ID);
            
            commands.Parameters.Add(para1);
            commands.Parameters.Add(para3);
            commands.Parameters.Add(para4);
            commands.Parameters.Add(para5);


            DataTable dt = _daoHelper.Query(commands);
            if (dt.Rows.Count > 0)
                return true;// Ton tai trung du lieu trong bang
            return false;
        }


        public bool CheckExistsOrg40(雇用情報 obj)
        {
            DbCommand commands = _daoHelper.CreateCommand("CheckExistsOrg40Vh", CommandType.StoredProcedure);

            DbParameter para1 = _daoHelper.CreateParameter("@雇用区分", obj.雇用区分_1);
            DbParameter para3 = _daoHelper.CreateParameter("@発令開始日", obj.発令開始日_1);
            DbParameter para4 = _daoHelper.CreateParameter("@実際開始日", obj.実際開始日_1);
            DbParameter para5 = _daoHelper.CreateParameter("@社員ID", obj.社員ID);
            DbParameter para6 = _daoHelper.CreateParameter("@ID", obj.ID);

            commands.Parameters.Add(para1);
            commands.Parameters.Add(para3);
            commands.Parameters.Add(para4);
            commands.Parameters.Add(para5);
            commands.Parameters.Add(para6);

            DataTable dt = _daoHelper.Query(commands);
            if (dt.Rows.Count > 0)
                return true;// Ton tai dong du lieu trong bang
            return false;
        }

        #endregion

    }
}
